(display "\n========================================\n")
(define (make-mobile left right)
    (list left right))

(define (make-branch length structure)
    (list length structure))

(define (left-branch m)
    (car m))

(define (right-branch m)
    (cadr m))

(define b1 (make-branch 3 4))
(define b2 (make-branch 4 3))
(define m (make-mobile b1 b2))
(display m)
(newline)
(display (left-branch m))
(newline)
(display (right-branch m))
(newline)

(define (branch-length b)
    (car b))

(define (branch-structure b)
    (cadr b))

(display (branch-length b2))
(newline)
(display (branch-structure b2))
(newline)

(define (hangs-another-mobile? b)
    (pair? (branch-structure b)))

(define (barnch-weight b)
    (if (hangs-another-mobile? b)
        (total-weight (branch-structure b))
        (branch-structure b)))

(define (total-weight m)
    (+ (barnch-weight (left-branch m))
       (barnch-weight (right-branch m))))

(display (total-weight m))
(newline)

(define (branch-torque b)
    (* (branch-length b)
       (barnch-weight b)))

(display (branch-torque b2))
(newline)

(define (mobile-balance? m)
    (let ((left (left-branch m))
          (right (right-branch m)))
        (and (same-torque? left right)
             (branch-balance? left)
             (branch-balance? right))))

(define (same-torque? left right)
    (= (branch-torque left)
       (branch-torque right)))

(define (branch-balance? b)
    (if (hangs-another-mobile? b)
        (mobile-balance? (branch-structure b))
        #t))

(display (mobile-balance? m))
(newline)

(define (left-branch mobile)
    (car mobile))

(define (right-branch mobile)
    (cdr mobile))

(define (branch-length branch)
    (car branch))

(define (branch-structure branch)
    (cdr branch))

(define (make-mobile left right)
    (cons left right))

(define (make-branch length structure)
    (cons length structure))

(define b1 (make-branch 3 4))
(define b2 (make-branch 4 3))
(define m (make-mobile b1 b2))
(display m)
(newline)

(display (mobile-balance? m))
(newline)

(display "\n========================================\n")
